#pragma once

#include "CUdpSession.h"
#include "CNetEventModleMgr.h"

class UdpSessionMgr
{
public:
	static UdpSessionMgr* UdpSessionMgrCreate();
	static int UdpSessionMgrDestroy();

	static int UdpSessionMgr_Init(int nNetEventModleIndex, int nNetEventModleThreadCount);
	static int UdpSessionMgr_Fini();

	int UdpSessionMgr_AddEvent(CUdpSession* pUdpSession);
	int UdpSessionMgr_DelEvent(CUdpSession* pUdpSession);

	int UdpSessionMgr_HandleData(LP_THREADINFO_T pThreadInfo);
#ifdef _WIN32
	bool AcceptSession_IsSocketAlive(SOCKET Socket);
	bool AcceptSession_HandleAcceptError(CUdpSession* pTcpSession, SOCKET Socket, const DWORD& dwErrno);
#endif
private:
	UdpSessionMgr();
	~UdpSessionMgr();
private:
	static vector<LP_THREADINFO_T> m_WorkThreadInfos;
	static int                     m_nNetEventModleThreadCount;
#ifndef _WIN32
	static int                      m_nHandleDataEpoll;
#else
	static HANDLE                  m_hHandleDataIOCP;
#endif
	static int                     m_nNetEventModleIndex;
	static mutex                   m_WorkThreadLock;
	static UdpSessionMgr* m_pUdpSessionMgr;
#ifndef _WINDOWS
	map<int, CUdpSession*> m_UdpSessions;
#else
	map<SOCKET, CUdpSession*> m_UdpSessions;
#endif
	mutex                     m_UdpSessionLock;
};

